/*
 * WorkPool.h
 *
 *  Created on: Nov 17, 2008
 *      Author: Ryan
 */

#ifndef WORKPOOL_H_
#define WORKPOOL_H_

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>

#include "WorkUnit.h"

#include <queue>

class WorkPool
{
public:
	WorkPool( int numWorkers );
	virtual ~WorkPool();

	void startWorkers();
	void stopWorkers();

	void submitWorkUnit( WorkUnit* work );
	WorkUnit* getWorkUnit();

private:
	int _numWorkers;
	boost::thread_group _workers;

	std::queue< WorkUnit* > _jobs;
	boost::mutex _mutex;
	boost::condition _jobQueueEmpty;


};

#endif /* WORKPOOL_H_ */
